# 1-导包
import pymysql

# 2-创建连接，获取连接对象
conn = pymysql.connect(host="211.103.136.244",user="student",password="KDTX_student_202304",
                       port=7068,database="huike",charset='utf8')
# 3-通过连接对象获取游标
cur = conn.cursor()
# 4-通过游标执行SQL
cur.execute("select * from tb_contract;")

# ①：查询tb_contract表第1条数据
# print(cur.fetchone())
print(cur.rownumber)
# ②：获取tb_ contract前3条数据
print(cur.fetchmany(3))
# ③：查询tb_ contract表的全部数据
print(cur.fetchall())

# 取中间某几条数据，第2条到第4条
cur.rownumber = 1  # 修改游标位置标识,默认从0开始
print(cur.fetchmany(3))
print(cur.rownumber)

# 5-关闭游标
cur.close()
# 6-关闭连接
conn.close()